const getFruit = async (name) => {
  const fruits = {
    pineapple: "🍍",
    peach: "🍑",
    strawberry: "🍓",
  };
  return Promise.resolve(fruits[name]);
};

// getFruit("peach").then(console.log);

const makeSmoothie = async () => {
  const a = await getFruit("pineapple");
  const b = await getFruit("strawberry");
  return [a, b];
};

// makeSmoothie().then(console.log);

const makeSmoothie2 = () => {
  let a;
  return getFruit("pineapple")
    .then((v) => {
      a = v;
      return getFruit("strawberry");
    })
    .then((v) => v + a);
};

// makeSmoothie2().then(console.log);

const makeSmoothie3 = async () => {
  try {
    const a = getFruit("pineapple");
    const b = getFruit("strawberry");
    const smoothie = Promise.all([a, b]);
    throw "broken!";
    return smoothie;
  } catch (err) {
    console.error(err);
    // return "🏴‍☠️ignore the error,provide replacement value";
    throw err
  }
};

makeSmoothie3().then(console.log).catch(err=>console.log);
